// 筛选动态路由数据的模块
import { asyncRoutes, constantRoutes } from '@/router/index'
const state = {
  routes: [] // 筛选出有访问权限的路由
}
const mutations = {
  // 保存筛选出来的路由
  SET_ROUTES(state, routes) {
    state.routes = [...constantRoutes, ...routes]
  }
}
const actions = {
  // 筛选路由
  filterRoutes(store, menus) {
    const routes = asyncRoutes.filter(item => {
      return menus.includes(item.code)
    })
    store.commit('SET_ROUTES', routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
